package com.gzsxy.esjy.common;

/**
 * 异常实现
 * @author zhangxiaolong
 * @date 2022/7/6 9:36
 */
public class SvException extends RuntimeException {

	private int exceptionCode ;
	
	private Throwable realException ;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4409904541331850076L;

	
	private SvException(String message) {
		super(message);
	}

	/**
	 * 获取实例
	 * @return
	 */
	public static SvException getInstance(String msg,Integer code,Throwable e) {
		// 获取一个新的的BusinessException变量
		SvException exception = new SvException(msg);
		exception.exceptionCode = code;
		exception.realException = (e == null?exception:e) ;
		return exception;
	}
	
	/**
	 * 获取实例
	 * @return
	 */
	public static SvException getInstance(String msg, Integer code) {
		return getInstance(msg, code, null) ;
	}
	
	/**
	 * 获取实例
	 * @return
	 */
	public static SvException getInstance(String msg, Throwable e) {
		return getInstance(msg, 500, e) ;
	}
	
	public Throwable getRealException() {
		return realException;
	}

	public int getExceptionCode() {
		return this.exceptionCode;
	}
	
	@Override
	public Throwable fillInStackTrace() {
		if(this.realException != null) {
			return super.fillInStackTrace();
		}
		return this;
	}

}
